/*!
\copyright  Copyright (c) 2021 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      Kymera header for LE Audio
*/

#ifndef KYMERA_LE_AUDIO_H_
#define KYMERA_LE_AUDIO_H_

#if defined(INCLUDE_LE_AUDIO_BROADCAST) || defined(INCLUDE_LE_AUDIO_UNICAST)

#include <kymera_adaptation_audio_protected.h>
#include <kymera_data.h>

/*! \brief The KYMERA_INTERNAL_LE_AUDIO_START_T message content. */
typedef struct
{
    bool media_present;
    bool microphone_present;
    bool reconfig;
    int16 volume_in_db;
    le_media_config_t media_params;
    le_microphone_config_t microphone_params;
} KYMERA_INTERNAL_LE_AUDIO_START_T;

/*! \brief The KYMERA_INTERNAL_LE_AUDIO_SET_VOLUME message content. */
typedef struct
{
    /*! The volume to set. */
    int16 volume_in_db;
} KYMERA_INTERNAL_LE_AUDIO_SET_VOLUME_T;

typedef struct
{
    rtime_t unmute_time;
} KYMERA_INTERNAL_LE_AUDIO_UNMUTE_T;

#if defined(INCLUDE_LE_AUDIO_BROADCAST_SOURCE) && defined (ENABLE_SIMPLE_SPEAKER)
/*! \brief To handle Le Audio broadcast request.
    \param enable TRUE/FALSE to enable/disable broadcast respectively.
*/
void KymeraLeAudio_HandleBroadcastRequest(bool enable);
#endif /* defined(INCLUDE_LE_AUDIO_BROADCAST_SOURCE) && defined (ENABLE_SIMPLE_SPEAKER) */

/*! \brief Handle request to start LE Audio.

    \param KYMERA_INTERNAL_LE_AUDIO_START_T params to configure the audio graph with
*/
void kymeraLeAudio_Start(const KYMERA_INTERNAL_LE_AUDIO_START_T * start_params);

/*! \brief Handle request to stop LE Audio.
*/
void kymeraLeAudio_Stop(void);

void kymeraLeAudio_SetVolume(int16 volume_in_db);

/*! \brief Checks if audio chain running has aptX adaptive decoder.
    \return TRUE if audio chain running has aptX adaptive decoder, else FALSE
*/
bool KymeraLeAudio_IsAptxAdaptiveStreaming(void);

/*! \brief Checks if multiperipheral cis is enabled.
    \return TRUE if multiperipheral cis is enabled, else FALSE
*/
bool KymeraLeAudio_IsMultiPeripheralCisEnabled(void);

/*! \brief Fetch QSS lossless data.
    \param lossless_data
    \return TRUE if fetch was was successful, else FALSE
*/
bool KymeraLeAudio_GetAptxAdaptiveLossLessInfo(uint32 *lossless_data);

#ifdef INCLUDE_MIRRORING
void KymeraLeAudio_HandleAudioUnmuteInd(const KYMERA_INTERNAL_LE_AUDIO_UNMUTE_T *unmute_params);
void KymeraLeAudio_ConfigureStartSync(kymeraTaskData *theKymera, bool start_muted);
#endif

void kymeraLeAudio_Init(void);

/*!
 * \brief Function to calculate the number of bits set.
          This function is used to calculate number of channels user selected and number of channels
          associated with a BIS/CIS
 * \param channel_to_render channels to render in BIS/CIS.
 * \return returns the  number of bits set in channel_to_render
 */
uint8 KymeraLeAudio_CalculateNumberOfChannels(uint32 channel_to_render);

/*!
 * \brief This function is used to configure decoder without using stream type.
          Based on channels to render the decoder is configured here.
 * \param op The end point operator.
 * \param media_params Le media parameter carrying channels to render.
 * \return Returns TRUE if decoder is configured, returns FALSE if decoder is not configured.
           If decoders ae not configured based on channel to render use stream type to configure decoders.

           Note:This funnction is usefull in multi channel, multi bis usecase where BIS/CIS carries two or more
           channels but user is interested in any of the channel.
           If a two BIS carries two channels each BIS1 (FL/FR), BIS2 (BL/BR). User may want to render
           FL/RL then This function configures the decoder to use only LEFT. Similarly depending on the
 */
bool kymeraLeDecoderBasedOnChannelToRender(Operator op, const le_media_config_t *media_params);

#else // INCLUDE_LE_AUDIO_BROADCAST) || INCLUDE_LE_AUDIO_UNICAST

#define KymeraLeAudio_IsAptxAdaptiveStreaming() (FALSE)

#define KymeraLeAudio_GetAptxAdaptiveLossLessInfo(lossless_data) (UNUSED(lossless_data), FALSE)

#endif // INCLUDE_LE_AUDIO_BROADCAST) || INCLUDE_LE_AUDIO_UNICAST
#endif // KYMERA_LE_AUDIO_H_
